package main

import (
	"flag"
	"fmt"
	"golang.org/x/net/webdav"
	"net/http"
)

func main() {
	addr, path := GetFlags()

	fmt.Printf("127.0.0.1%s", *addr)

	NewServe(addr, path)
}

func NewServe(addr *string, path *string) (err error) {
	err = http.ListenAndServe(*addr, &webdav.Handler{
		FileSystem: webdav.Dir(*path),
		LockSystem: webdav.NewMemLS(),
	})
	return
}

func GetFlags() (*string, *string) {
	var addr *string
	var path *string
	// 获取命令行参数
	addr = flag.String("addr", ":8080", "")
	path = flag.String("path", ".", "")
	flag.Parse()
	return addr, path
}
